package com.zhoukx.factory.absfactory.pizzstore.order;

import com.zhoukx.factory.absfactory.pizzstore.pizze.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @ClassName OrderPizza
 * @Description:
 * @Author zhoukx
 * @Date 2020/8/6
 **/
public class OrderPizza  {
    AbsFactory absFactory;

    public OrderPizza(AbsFactory absFactory){
        setAbsFactory(absFactory);
    }


    private void setAbsFactory(AbsFactory absFactory){
        Pizza pizza = null;
        String orderType="";
        this.absFactory = absFactory;
        do{
            orderType = gettype();
            pizza = absFactory.createPizeea(orderType);
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购失败");
                break;
            }
        }while (true);
    }


    // 写一个方法 动态获取客户希望订购的披萨种类
    private String gettype() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
